//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "MakeCapFloor.h"
using namespace Cephei::QL::Instruments;
#include <gen/QL/Times/Period.h>
#include <gen/QL/Indexes/IborIndex.h>
#include <gen/QL/Instruments/CapFloor.h>
#include <gen/QL/Times/Calendar.h>
#include <gen/QL/Times/DayCounter.h>
#include <gen/QL/PricingEngine.h>
using namespace Cephei::QL::Times;
using namespace Cephei::QL::Indexes;
using namespace Cephei::QL;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Instruments::CMakeCapFloor::CMakeCapFloor (QL::Instruments::CapFloor::TypeEnum capFloorType, Cephei::QL::Times::IPeriod^ capFloorTenor, Cephei::QL::Indexes::IIborIndex^ iborIndex, Microsoft::FSharp::Core::FSharpOption<Double>^ strike, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>^ forwardStart) 
{
	_pSpinlock = new boost::detail::spinlock ();
    CPeriod^ _CcapFloorTenor;
    CIborIndex^ _CiborIndex;
    CPeriod^ _CforwardStart;
    try
    {
#ifdef HANDLE
        _phMakeCapFloor = NULL;
#endif
        QuantLib::CapFloor::Type _capFloorType = (QuantLib::CapFloor::Type)capFloorType ;
        _CcapFloorTenor = safe_cast<CPeriod^> (capFloorTenor);
        _CcapFloorTenor->Lock();
        QuantLib::Period& _capFloorTenor = static_cast<QuantLib::Period&> (_CcapFloorTenor->GetReference ()); 
        _CiborIndex = safe_cast<CIborIndex^> (iborIndex);
        _CiborIndex->Lock();
        boost::shared_ptr<QuantLib::IborIndex>& _iborIndex = static_cast<boost::shared_ptr<QuantLib::IborIndex>&> (_CiborIndex->GetShared ()); 
        QuantLib::Rate _strike = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (strike) ? (QuantLib::Rate)ValueHelper::Convert (strike->Value) : Null<QuantLib::Rate>()); //4
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>::IsSome::get (forwardStart))
        {
            _CforwardStart = safe_cast<CPeriod^> (forwardStart->Value);
            _CforwardStart->Lock();
        }
        QuantLib::Period& _forwardStart = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>::IsSome::get (forwardStart) ? static_cast<QuantLib::Period&> (_CforwardStart->GetReference ()) : 0*Days); //1
        _ppMakeCapFloor = new boost::shared_ptr<QuantLib::MakeCapFloor> (new QuantLib::MakeCapFloor ( _capFloorType,  _capFloorTenor,  _iborIndex,  _strike,  _forwardStart ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_CcapFloorTenor != nullptr) _CcapFloorTenor->Unlock();
        if (_CiborIndex != nullptr) _CiborIndex->Unlock();
        if (_CforwardStart != nullptr) _CforwardStart->Unlock();
    }
}
Cephei::QL::Instruments::CMakeCapFloor::CMakeCapFloor (boost::shared_ptr<QuantLib::MakeCapFloor>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phMakeCapFloor = NULL;
#endif
	_ppMakeCapFloor = &childNative;
    
}
Cephei::QL::Instruments::CMakeCapFloor::CMakeCapFloor (QuantLib::MakeCapFloor& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phMakeCapFloor = NULL;
#endif
	_ppMakeCapFloor = new boost::shared_ptr<QuantLib::MakeCapFloor> (&childNative);
    
    _MakeCapFloorOwner = owner;
    
}

Cephei::QL::Instruments::CMakeCapFloor::CMakeCapFloor (CMakeCapFloor^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phMakeCapFloor = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppMakeCapFloor = new boost::shared_ptr<QuantLib::MakeCapFloor> (copy->GetShared());
        
    }
}
Cephei::QL::Instruments::CMakeCapFloor::CMakeCapFloor (System::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phMakeCapFloor = NULL;
#endif
	if (!t->IsSubclassOf(CMakeCapFloor::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Instruments::CMakeCapFloor::CMakeCapFloor (QuantLib::Handle<QuantLib::MakeCapFloor>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phMakeCapFloor = &childNative;
	_ppMakeCapFloor = &static_cast<boost::shared_ptr<QuantLib::MakeCapFloor>>(childNative.currentLink());
    
    _MakeCapFloorOwner = owner;
}
Cephei::QL::Instruments::CMakeCapFloor::CMakeCapFloor (QuantLib::Handle<QuantLib::MakeCapFloor> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phMakeCapFloor = &childNative;
	_ppMakeCapFloor = &static_cast<boost::shared_ptr<QuantLib::MakeCapFloor>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Instruments::CMakeCapFloor::CMakeCapFloor (QuantLib::MakeCapFloor childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phMakeCapFloor = NULL;
#endif
	_ppMakeCapFloor = new boost::shared_ptr<QuantLib::MakeCapFloor> (new QuantLib::MakeCapFloor (childNative));
    
}
#endif

Cephei::QL::Instruments::CMakeCapFloor::~CMakeCapFloor ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppMakeCapFloor != NULL)
    {
	    delete _ppMakeCapFloor;
        _ppMakeCapFloor = NULL;
    }
}
Cephei::QL::Instruments::CMakeCapFloor::!CMakeCapFloor ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppMakeCapFloor != NULL)
    {
	    delete _ppMakeCapFloor;
    }
}
QuantLib::MakeCapFloor& Cephei::QL::Instruments::CMakeCapFloor::GetReference ()
{
    if (_ppMakeCapFloor == NULL) throw gcnew NativeNullException ();
	return **_ppMakeCapFloor;
}
boost::shared_ptr<QuantLib::MakeCapFloor>& Cephei::QL::Instruments::CMakeCapFloor::GetShared ()
{
    if (_ppMakeCapFloor == NULL) throw gcnew NativeNullException ();
	return *_ppMakeCapFloor;
}
QuantLib::MakeCapFloor* Cephei::QL::Instruments::CMakeCapFloor::GetPointer ()
{
    if (_ppMakeCapFloor == NULL) throw gcnew NativeNullException ();
	return &**_ppMakeCapFloor;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::MakeCapFloor>& Cephei::QL::Instruments::CMakeCapFloor::GetHandle ()
{
	if (_phMakeCapFloor == NULL)
	{
		_phMakeCapFloor = new Handle<QuantLib::MakeCapFloor> (*_ppMakeCapFloor);
	}
	return *_phMakeCapFloor;
}
#endif
bool Cephei::QL::Instruments::CMakeCapFloor::HasNative () 
{
	return (_ppMakeCapFloor != NULL);
}

Cephei::QL::Instruments::IMakeCapFloor^ Cephei::QL::Instruments::CMakeCapFloor::WithCalendar (Cephei::QL::Times::ICalendar^ cal)
{
    CCalendar^ _Ccal;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        _Ccal = safe_cast<CCalendar^> (cal);
        _Ccal->Lock();
        QuantLib::Calendar& _cal = static_cast<QuantLib::Calendar&> (_Ccal->GetReference ()); 
    	QuantLib::MakeCapFloor& _rv = (QuantLib::MakeCapFloor&)(*_ppMakeCapFloor)->withCalendar ( _cal );   
        Cephei::QL::Instruments::CMakeCapFloor^ _nrv = gcnew Cephei::QL::Instruments::CMakeCapFloor (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_Ccal != nullptr) _Ccal->Unlock();
    }
}
Cephei::QL::Instruments::IMakeCapFloor^ Cephei::QL::Instruments::CMakeCapFloor::WithConvention (QL::Times::BusinessDayConventionEnum bdc)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::BusinessDayConvention _bdc = (QuantLib::BusinessDayConvention)bdc ;
    	QuantLib::MakeCapFloor& _rv = (QuantLib::MakeCapFloor&)(*_ppMakeCapFloor)->withConvention ( _bdc );   
        Cephei::QL::Instruments::CMakeCapFloor^ _nrv = gcnew Cephei::QL::Instruments::CMakeCapFloor (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeCapFloor^ Cephei::QL::Instruments::CMakeCapFloor::WithDayCount (Cephei::QL::Times::IDayCounter^ dc)
{
    CDayCounter^ _Cdc;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        _Cdc = safe_cast<CDayCounter^> (dc);
        _Cdc->Lock();
        QuantLib::DayCounter& _dc = static_cast<QuantLib::DayCounter&> (_Cdc->GetReference ()); 
    	QuantLib::MakeCapFloor& _rv = (QuantLib::MakeCapFloor&)(*_ppMakeCapFloor)->withDayCount ( _dc );   
        Cephei::QL::Instruments::CMakeCapFloor^ _nrv = gcnew Cephei::QL::Instruments::CMakeCapFloor (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cdc != nullptr) _Cdc->Unlock();
    }
}
Cephei::QL::Instruments::IMakeCapFloor^ Cephei::QL::Instruments::CMakeCapFloor::WithEffectiveDate (DateTime effectiveDate, Boolean firstCapletExcluded)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::Date _effectiveDate = (QuantLib::Date)ValueHelper::Convert (effectiveDate);
        bool _firstCapletExcluded = (bool)ValueHelper::Convert (firstCapletExcluded);
    	QuantLib::MakeCapFloor& _rv = (QuantLib::MakeCapFloor&)(*_ppMakeCapFloor)->withEffectiveDate ( _effectiveDate,  _firstCapletExcluded );   
        Cephei::QL::Instruments::CMakeCapFloor^ _nrv = gcnew Cephei::QL::Instruments::CMakeCapFloor (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeCapFloor^ Cephei::QL::Instruments::CMakeCapFloor::WithEndOfMonth (Microsoft::FSharp::Core::FSharpOption<Boolean>^ flag)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        bool _flag = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (flag) ? (bool)ValueHelper::Convert (flag->Value) : true); //9a
    	QuantLib::MakeCapFloor& _rv = (QuantLib::MakeCapFloor&)(*_ppMakeCapFloor)->withEndOfMonth ( _flag );   
        Cephei::QL::Instruments::CMakeCapFloor^ _nrv = gcnew Cephei::QL::Instruments::CMakeCapFloor (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeCapFloor^ Cephei::QL::Instruments::CMakeCapFloor::WithFirstDate (DateTime d)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::Date _d = (QuantLib::Date)ValueHelper::Convert (d);
    	QuantLib::MakeCapFloor& _rv = (QuantLib::MakeCapFloor&)(*_ppMakeCapFloor)->withFirstDate ( _d );   
        Cephei::QL::Instruments::CMakeCapFloor^ _nrv = gcnew Cephei::QL::Instruments::CMakeCapFloor (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeCapFloor^ Cephei::QL::Instruments::CMakeCapFloor::WithNextToLastDate (DateTime d)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::Date _d = (QuantLib::Date)ValueHelper::Convert (d);
    	QuantLib::MakeCapFloor& _rv = (QuantLib::MakeCapFloor&)(*_ppMakeCapFloor)->withNextToLastDate ( _d );   
        Cephei::QL::Instruments::CMakeCapFloor^ _nrv = gcnew Cephei::QL::Instruments::CMakeCapFloor (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeCapFloor^ Cephei::QL::Instruments::CMakeCapFloor::WithNominal (Double n)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::Real _n = (QuantLib::Real)ValueHelper::Convert (n);
    	QuantLib::MakeCapFloor& _rv = (QuantLib::MakeCapFloor&)(*_ppMakeCapFloor)->withNominal ( _n );   
        Cephei::QL::Instruments::CMakeCapFloor^ _nrv = gcnew Cephei::QL::Instruments::CMakeCapFloor (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeCapFloor^ Cephei::QL::Instruments::CMakeCapFloor::WithPricingEngine (Cephei::QL::IPricingEngine^ engine)
{
    CPricingEngine^ _Cengine;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        _Cengine = safe_cast<CPricingEngine^> (engine);
        _Cengine->Lock();
        boost::shared_ptr<QuantLib::PricingEngine>& _engine = static_cast<boost::shared_ptr<QuantLib::PricingEngine>&> (_Cengine->GetShared ()); 
    	QuantLib::MakeCapFloor& _rv = (QuantLib::MakeCapFloor&)(*_ppMakeCapFloor)->withPricingEngine ( _engine );   
        Cephei::QL::Instruments::CMakeCapFloor^ _nrv = gcnew Cephei::QL::Instruments::CMakeCapFloor (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cengine != nullptr) _Cengine->Unlock();
    }
}
Cephei::QL::Instruments::IMakeCapFloor^ Cephei::QL::Instruments::CMakeCapFloor::WithRule (QL::Times::DateGeneration::RuleEnum r)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::DateGeneration::Rule _r = (QuantLib::DateGeneration::Rule)r ;
    	QuantLib::MakeCapFloor& _rv = (QuantLib::MakeCapFloor&)(*_ppMakeCapFloor)->withRule ( _r );   
        Cephei::QL::Instruments::CMakeCapFloor^ _nrv = gcnew Cephei::QL::Instruments::CMakeCapFloor (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeCapFloor^ Cephei::QL::Instruments::CMakeCapFloor::WithTenor (Cephei::QL::Times::IPeriod^ t)
{
    CPeriod^ _Ct;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        _Ct = safe_cast<CPeriod^> (t);
        _Ct->Lock();
        QuantLib::Period& _t = static_cast<QuantLib::Period&> (_Ct->GetReference ()); 
    	QuantLib::MakeCapFloor& _rv = (QuantLib::MakeCapFloor&)(*_ppMakeCapFloor)->withTenor ( _t );   
        Cephei::QL::Instruments::CMakeCapFloor^ _nrv = gcnew Cephei::QL::Instruments::CMakeCapFloor (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_Ct != nullptr) _Ct->Unlock();
    }
}
Cephei::QL::Instruments::IMakeCapFloor^ Cephei::QL::Instruments::CMakeCapFloor::WithTerminationDateConvention (QL::Times::BusinessDayConventionEnum bdc)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::BusinessDayConvention _bdc = (QuantLib::BusinessDayConvention)bdc ;
    	QuantLib::MakeCapFloor& _rv = (QuantLib::MakeCapFloor&)(*_ppMakeCapFloor)->withTerminationDateConvention ( _bdc );   
        Cephei::QL::Instruments::CMakeCapFloor^ _nrv = gcnew Cephei::QL::Instruments::CMakeCapFloor (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeCapFloor^ Cephei::QL::Instruments::CMakeCapFloor::AsOptionlet (Microsoft::FSharp::Core::FSharpOption<Boolean>^ b)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        bool _b = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (b) ? (bool)ValueHelper::Convert (b->Value) : true); //9a
    	QuantLib::MakeCapFloor& _rv = (QuantLib::MakeCapFloor&)(*_ppMakeCapFloor)->asOptionlet ( _b );   
        Cephei::QL::Instruments::CMakeCapFloor^ _nrv = gcnew Cephei::QL::Instruments::CMakeCapFloor (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Instruments::IMakeCapFloor^ Cephei::QL::Instruments::CMakeCapFloor_Factory::Create (QL::Instruments::CapFloor::TypeEnum capFloorType, Cephei::QL::Times::IPeriod^ capFloorTenor, Cephei::QL::Indexes::IIborIndex^ iborIndex, Microsoft::FSharp::Core::FSharpOption<Double>^ strike, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>^ forwardStart)
{
    return gcnew CMakeCapFloor ( capFloorType,  capFloorTenor,  iborIndex,  strike,  forwardStart);
}
